using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using ENTITIES;
using BUS;
using Utility;

public partial class admin_DanhSachNhanVien : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        LoadData();
    }
    private void LoadData()
    {
        PagerV2_8_1.PageSize = 2;
        Criteria c = new Criteria();
        if (txt_MaNV.Text != "")
        {
            c.add(Condition.AND, tbNhanVienColumns.MaNV, Condition.LIKE, txt_MaNV.Text);
        }
        if (txt_TenNV.Text != "")
        {
            c.add(Condition.AND, tbNhanVienColumns.TenNV, Condition.LIKE, txt_TenNV.Text);
        }
        int total = 0;
        tbNhanVienCollection nhanviencollection =
            NhanVienBUS.Get(c.Criter, PagerV2_8_1.CurrentIndex, PagerV2_8_1.PageSize,
            tbNhanVienColumns.MaNV.ToString(), OrderDirection.ASC.ToString(), out total);
        Repeater1.DataSource = nhanviencollection;
        Repeater1.DataBind();
        PagerV2_8_1.ItemCount = total;
    }
    protected void lbt_Xoa_Click(object sender, EventArgs e)
    {

        for (int i = 0; i < Repeater1.Items.Count; i++)
        {
            CheckBox cb_Xoa = (CheckBox)Repeater1.Items[i].FindControl("cb_Xoa");
            if (cb_Xoa.Checked == true)
            {
                HiddenField hf_id = (HiddenField)Repeater1.Items[i].FindControl("hf_id");
                int id = int.Parse(hf_id.Value);
                TBNhanVien nhanvien = NhanVienBUS.GetByID(id);

                NhanVienBUS.Delete(id);
            }
        }
        Response.Redirect(Request.RawUrl);
    }
    protected void Repeater1_ItemDataBound(object sender, RepeaterItemEventArgs e)
    {
        if (e.Item.ItemType == ListItemType.AlternatingItem ||
        e.Item.ItemType == ListItemType.Item)
        {
            TBNhanVien nhanvien = (TBNhanVien)e.Item.DataItem;
            HyperLink hyp_TenNV = (HyperLink)e.Item.FindControl("hyp_TenNV");

            hyp_TenNV.Text = nhanvien.tennv;
            hyp_TenNV.NavigateUrl = "~/admin/ChiTietNhanVien.aspx?id=" + nhanvien.manv.ToString();

            HyperLink hpl_Edit = (HyperLink)e.Item.FindControl("hpl_Edit");
            hpl_Edit.NavigateUrl = "~/admin/SuaNhanVien.aspx?id=" + nhanvien.manv.ToString();
        }
    }
    protected void PagerV2_8_1_Command(object sender, CommandEventArgs e)
    {
        PagerV2_8_1.CurrentIndex = int.Parse(e.CommandArgument.ToString());
        LoadData();
    }
    protected void btn_timkiem_Click(object sender, EventArgs e)
    {
        LoadData();
    }
}
